<template>
  <div class="app-container">
    <h1 ref="myh1">App 根组件</h1>
    <h2 ref="myh2">App 根组件</h2>
    <button @click="showThis">打印 this</button>
    <button @click="resetCount">重置count</button>
    <hr>

    <input type="text" v-if="flag" ref="iptRef" @blur="showButton">
    <button v-else @click="showInput">展示输入框</button>

    <hr>

    <div class="box">
      <!-- 使用ref操作组件 -->
      <LeftComponent ref="left"></LeftComponent>

    </div>
  </div>
</template>

<script>
import LeftComponent from '@/components/Left.vue'

export default {
  data(){
    return {
      flag: false,
    }
  },
  methods:{
    showThis(){
      console.log(this);
      console.log(this.$refs);
      console.log(this.$refs.myh1);
      console.log(this.$refs.myh2);
      this.$refs.myh1.style.color='red';
    },
    resetCount(){
      this.$refs.left.resetCount(); 
    },
    showInput(){
      this.flag = true;
      this.$nextTick(()=>{
        this.$refs.iptRef.focus()
      });
    },
    showButton(){
      this.flag = false;
    }
  },
  components:{
    LeftComponent
  }
}
</script>

<style lang="less">
.app-container {
  padding: 1px 20px 20px;
  background-color: #efefef;
}
.box {
  display: flex;
}
</style>
